package com.ruoyi.system.controller;

import java.util.List;
import javax.annotation.Resource;

import com.ruoyi.system.domain.dto.*;
import com.ruoyi.system.domain.vo.EnterpriseViewVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.Order;
import com.ruoyi.system.service.IOrderService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 单据Controller
 *
 * @author 协同
 * @date 2022-04-18
 */
@RestController
@RequestMapping("/system/order")
public class OrderController extends BaseController {
    @Resource
    private IOrderService orderService;

    /**
     * 企业查询采购申请订单列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Order order) {
        startPage();
        List<Order> list = orderService.selectOrderList(order);
        return getDataTable(list);
    }

    /**
     * 企业查询采购订单和采购退料单列表
     */
    @GetMapping("/getEnterpriseList")
    public TableDataInfo getEnterpriseList(Order order) {
        startPage();
        List<Order> list = orderService.getEnterpriseList(order);
        return getDataTable(list);
    }

    /**
     * 企业查询采购订单视图
     */
    @GetMapping("/getEnterpriseView")
    public AjaxResult getEnterpriseView(Order order) {
        return AjaxResult.success(orderService.getEnterpriseView(order));
    }

    /**
     * 供应商查询采购订单和采购退料单列表
     */
    @GetMapping("/getSupplierList")
    public TableDataInfo getSupplierList(Order order) {
        startPage();
        List<Order> list = orderService.getSupplierList(order);
        return getDataTable(list);
    }

    /**
     * 供应商查询采购订单视图
     */
    @GetMapping("/getSupplierView")
    public AjaxResult getSupplierView(Order order) {
        return AjaxResult.success(orderService.getSupplierView(order));
    }

    /**
     * 供应商查询询价单据列表
     */
    @GetMapping("/xjList")
    public TableDataInfo xjList(Order order) {
        startPage();
        List<Order> list = orderService.selectOrderXJList(order);
        return getDataTable(list);
    }

    /**
     * 供应商查询采购订单列表
     */
    @GetMapping("/cgList")
    public TableDataInfo cgList(Order order) {
        startPage();
        List<Order> list = orderService.cgList(order);
        return getDataTable(list);
    }

    /**
     * 供应商查询收料通知订单列表
     */
    @GetMapping("/sltzList")
    public TableDataInfo sltzList(Order order) {
        startPage();
        List<Order> list = orderService.sltzList(order);
        return getDataTable(list);
    }

    /**
     * 供应商查询采购入库订单列表
     */
    @GetMapping("/cgrkOrder")
    public TableDataInfo cgrkOrder(Order order) {
        startPage();
        List<Order> list = orderService.cgrkOrder(order);
        return getDataTable(list);
    }

    /**
     * 供应商查询退料通知订单列表
     */
    @GetMapping("/tltzcxOrder")
    public TableDataInfo tltzcxOrder(Order order) {
        startPage();
        List<Order> list = orderService.tltzcxOrder(order);
        return getDataTable(list);
    }

    /**
     * 供应商采购退料通知订单列表
     */
    @GetMapping("/cgtlcxOrder")
    public TableDataInfo cgtzcxOrder(Order order) {
        startPage();
        List<Order> list = orderService.cgtzcxOrder(order);
        return getDataTable(list);
    }

    /**
     * 获取单据详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(orderService.selectOrderById(id));
    }

    /**
     * 新增单据
     */
    @PostMapping
    public AjaxResult add(@RequestBody Order order) {
        return toAjax(orderService.insertOrder(order));
    }

    /**
     * 新增询价单据
     */
    @PostMapping("/xjOrder")
    public AjaxResult xjOrder(@RequestBody XJOrderDTO dto) {
        return toAjax(orderService.xjOrder(dto));
    }

    /**
     * 新增报价单据
     */
    @PostMapping("/bjOrder")
    public AjaxResult bjOrder(@RequestBody BJOrderDTO dto) {
        return toAjax(orderService.bjOrder(dto));
    }

    /**
     * 新增采购订单
     */
    @PostMapping("/purchaseOrder")
    public AjaxResult purchaseOrder(@RequestBody OrderByIdDTO dto) {
        return toAjax(orderService.purchaseOrder(dto));
    }

    /**
     * 新增收料通知订单
     */
    @PostMapping("/addReceipt")
    public AjaxResult addReceipt(@RequestBody OrderByIdDTO dto) {
        return toAjax(orderService.addReceipt(dto));
    }

    /**
     * 新增采购入库订单
     */
    @PostMapping("/warehousing")
    public AjaxResult warehousing(@RequestBody OrderByIdDTO dto) {
        return toAjax(orderService.warehousing(dto));
    }

    /**
     * 更新库存
     */
    @PostMapping("/addStock")
    public AjaxResult addStock(@RequestBody OrderByIdDTO dto) {
        return toAjax(orderService.addStock(dto));
    }

    /**
     * 更新库存
     */
    @PostMapping("/updateStock")
    public AjaxResult updateStock(@RequestBody OrderByIdDTO dto) {
        return toAjax(orderService.updateStock(dto));
    }

    /**
     * 新增退料通知订单
     */
    @PostMapping("/returnMaterial")
    public AjaxResult returnMaterial(@RequestBody ReturnOrderDTO dto) {
        return toAjax(orderService.returnMaterial(dto));
    }

    /**
     * 新增采购退料订单
     */
    @PostMapping("/addPurchaseReturn")
    public AjaxResult addPurchaseReturn(@RequestBody OrderByIdDTO dto) {
        return toAjax(orderService.addPurchaseReturn(dto));
    }

    /**
     * 查看报价
     */
    @GetMapping("/searchQuote")
    public AjaxResult searchQuote(OrderByIdDTO dto) {
        return AjaxResult.success(orderService.searchQuote(dto));
    }

    /**
     * 修改单据
     */
    @PutMapping
    public AjaxResult edit(@RequestBody Order order) {
        return toAjax(orderService.updateOrder(order));
    }

    /**
     * 修改单据
     */
    @PutMapping("/allOrder")
    public AjaxResult allOrder(@RequestBody OrderDTO dto) {
        return toAjax(orderService.updateAllOrder(dto));
    }

    /**
     * 删除单据
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(orderService.deleteOrderByIds(ids));
    }
}
